
using System;
using Gtk;
using iPuz.Game;

namespace iPuz.Gui {

	public partial class win : Gtk.Window
	{
		uint _moveCounter = 0;
		
		public win () : base(Gtk.WindowType.Toplevel)
		{
			this.Build ();
			StartTheGame();
		}
		
		private void StartTheGame()
		{
			// TODO: check the file image
			// TODO: Fix the imageMainPic Width_x_Height relativity.
			string filename = AppDomain.CurrentDomain.BaseDirectory + "pics/1.png";
			_imgMainPic.Pixbuf = new Gdk.Pixbuf (filename).ScaleSimple(180, 180, Gdk.InterpType.Hyper);
			
			GameLoader gl = new GameLoader (_tblPlay);
			gl.GameLoaderAction += OnGameLoader_Action;
			gl.Start(filename);
		}
		
		private void OnGameLoader_Action (object sender, bool go)
		{
			_moveCounter++;
			_lblMovesRecord.Text = _moveCounter.ToString() + " move(s)";
			
//			if (go) {
				WinScore ws = new WinScore (_moveCounter);
				ws.Run();								// Congratulations
				ws.Destroy();
				// TODO: remove _lblGameOver
//			}
		}
		
		
		// Close the main window and exit the program
		protected virtual void OnWin_Closed (object sender, Gtk.DeleteEventArgs args)
		{
			Application.Quit();
			args.RetVal = true;
		}
		
		[STAThread]
		public static void Main ()
		{
			Application.Init();
			new win();
			Application.Run();
		}
		
		protected virtual void OnMnGameQuit_Activted (object sender, System.EventArgs args)
		{
			Application.Quit();
		}		
		
	}
}
